<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="el.User"%>
<%@page import="el.Card"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'user.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	</head>

	<body>
		<%
			User user = new User();
			user.setAge(18);
			user.setName("ligang");
			Card card = new Card();
			card.setCardNo("1");
			user.setCard(card);
			//request.setAttribute("user", user);//对于标签，先到request里找，未找到向下找
			session.setAttribute("user", user);//未找到，再到request里找
			
		%>
		user's name
		<%
			//User ligang = (User) request.getAttribute("user");
			//out.println(ligang.getName());
		%>
		<%-- ${user["name"]作用与下面相同，这种方式允许  中括号  里的内容是一个变量，下面不行 --%>
		<%--  中括号  里的内容是一个变量,如果属性是一个数组，可以使用${user.interest[0] --%>
		${user.name }<%-- 当user为null或为给name赋值时，不输出内容； --%>
		<%-- user相当于request.getAttribute("user", user); 
			.name相当于调用user的getName()方法
		--%>
		<br/>
		user's cardNo:${user.card.cardNo }
		<br/>
		${requestScope.user.card.cardNo }<%-- 只在request里找 --%>
		
		<%
			User ligangerzi = new User();
			ligangerzi.setAge(18);
			ligangerzi.setName("ligangerzi");
			String[] interests= new String[]{"kaiche","zhangren","jiaowobashiligang"};
			ligangerzi.setInterests(interests);
			request.setAttribute("ligangerzi", ligangerzi);
			request.setAttribute("tabashiligang","name");
			
		%>
		<br/>
		ligangerzi's name : ${ligangerzi["name"] }
		<br/>
		ligangerzi's name : ${ligangerzi[tabashiligang] }
		<br/>
		ligangerzi's interests:${ ligangerzi.interests[0]}
	</body>
</html>
